//
//  HomeViewController.m
//  yunqiphone
//
//  Created by IreWesT on 15/5/18.
//  Copyright (c) 2015年 ci123.com. All rights reserved.
//

#import "HomeViewController.h"


#define TagBaseCate         500
#define TagBaseCateTitle    600
#define TagBaseCateIcon     700
#define TagBaseFunction     800
#define TagAdBack           3001


@implementation HomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        if (Current_device_vesion < 7.0) {
            [[UIApplication sharedApplication] setStatusBarHidden:NO];
        }
        self.canBack = NO;
        self.isTarView = YES;
    }
    return self;
}


- (void)viewDidLoad {
    
    [super viewDidLoad];
    if (Current_device_vesion >= 7.0) {
        [self.tabBarController.tabBar setTranslucent:NO];
    }
    [self _initNavView];
    [self _initView];
    [self _initHeadView];
    [self _initCateView];
    [self _initAdsView];
}

//中间8个版块
-(void)_initCateView {
    CGFloat height = 220.0f;
    _cateView = [[UIView alloc] initWithFrame:CGRectMake(0, _headView.bottom, _scrollContentView.width, height)]; //整个区域放在cateView里面
    _cateView.backgroundColor = [UIColor whiteColor];
    [_scrollContentView addSubview:_cateView];  //还是要把cateView添加进tableview的headerview里面
    
    NSArray *titles=@[@"同龄圈",@"同城圈",@"热帖",@"今日知识",@"宝宝衣橱",@"不能吃",@"品牌屋",@"好友圈"];
    _topTitles = [NSMutableArray arrayWithArray:titles];
    CGFloat oMarginX = 5.0f, oMarginY = 14.0f, gap = 0.0f;//设置每个块之间的间距
    CGFloat viewWidth = ((APP_SCREEN_WIDTH - oMarginX * 2) / 4), viewheight = (height - oMarginY * 2 - gap) / 2; //计算每个块的宽度和高度
    CGFloat iconLength = 45.0f;
    
    CGFloat marginX = oMarginX, marginY = oMarginY;
    for(int i = 0; i < [_topTitles count]; i++) {
        //初始化每一个块 UIView 坐标和背景 以及设置点击事件
        UIView *winphone = [[UIView alloc] initWithFrame:CGRectMake(marginX, marginY, viewWidth, viewheight)];
        winphone.tag = TagBaseCate + i;
        winphone.backgroundColor = [UIColor whiteColor];
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushCateController:)];
//        [winphone addGestureRecognizer:tap];
        
        //初始化每个块里面的图标
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((viewWidth - iconLength) / 2, 15, iconLength, iconLength)];
        icon.backgroundColor = [UIColor clearColor];
        icon.tag = TagBaseCateIcon;
        [winphone addSubview:icon];
        //初始化每个块里面的标签文字
        UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, icon.bottom + 10, viewWidth, 14)];
        title.backgroundColor = [UIColor clearColor];
        title.textAlignment = NSTextAlignmentCenter;
        title.tag = TagBaseCateTitle;
        title.font=[UIFont systemFontOfSize:13.5];
        title.textColor = RGBCOLOR(135, 123, 111);
        title.text = titles[i];
        [winphone addSubview:title];
        //是否是最后一个 ，如果是的话，块的右侧就不要显示竖线
        BOOL isLastNetIconShow = NO;
        if (UDIsLastNetIconShow && [[NSString stringWithFormat:@"%@", UDIsLastNetIconShow]isEqualToString:@"1"]) {
            isLastNetIconShow = YES;
        }
        //设置icon的图片
        NSString *imageString;//图片名称
        BOOL isLastBrandShow = NO;
        if(AppScreenInchType == AppScreenInch5_5){//针对大屏手机的图标比较大
            imageString = [NSString stringWithFormat:@"home_icon55_%d",i + 1];
            if (i == 6 && isLastBrandShow) {
                imageString = @"home_icon55_brand";
            }
            if(i==4){
                imageString = @"home_icon55_school";
            }
            if(i==5){
                imageString = @"home_icon55_food";
            }
        }else {
            imageString = [NSString stringWithFormat:@"home_icon47_%d",i + 1];
            if (i == 6 && isLastBrandShow) {
                imageString = @"home_icon47_brand";
            }
            if(i==4 ){
                imageString = @"home_icon47_school";
            }
            if(i==5 ){
                imageString = @"home_icon47_food";
            }
        }
        [icon setImage:[UIImage imageNamed:imageString]];
        //设置块左侧的竖线，最左边不设置竖线
        if (i != 0 && i != 4) {//left border
            CALayer *border = [CALayer layer];
            border.frame = CGRectMake(0, 15, .5f, viewheight - 15 * 2);//1pt = 2px
            border.backgroundColor = RGBCOLOR(240, 238, 238).CGColor;
            [winphone.layer addSublayer:border];
            
        }
        //设置块下面的横线，但是只是针对第一行有横线
        if (i < 4) {//bottom border
            CALayer *border = [CALayer layer];
            border.frame = CGRectMake(10, viewheight - .5f, viewWidth - 10 * 2, .5f);
            border.backgroundColor = RGBCOLOR(240, 238, 238).CGColor;
            [winphone.layer addSublayer:border];
        }
        //重新计算定位下一个块的坐标
        if(i == 3) {
            marginY = winphone.bottom + gap;
            
            marginX = oMarginX;
        }else {
            marginX += winphone.width;
        }
        [_cateView addSubview:winphone];
    }
}

//广告位
- (void)_initAdsView {
    //定义广告图的宽度和高度，使用屏幕的宽，然后通过比例，算出高度，这样就可以避免广告图是被拉伸变形
    CGFloat width = APP_SCREEN_WIDTH;
    CGFloat height = width / 3.2;
    
    _adsView = [[UIView alloc] initWithFrame:CGRectMake(0, _cateView.bottom + 15, _scrollContentView.width, height)];
    _adsView.backgroundColor = [UIColor clearColor];
    [_scrollContentView addSubview:_adsView];
    
    //默认背景，当在没有网络的情况下，可以看到背景图
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [backImage setImage:[UIImage imageNamed:@"ads_default"]];
    backImage.tag = TagAdBack;
    [_adsView addSubview:backImage];
    
    NSArray *_adsData = @[@{
        @"id":@(2045),
        @"pic200": @"http://www.qubaobei.com/ios/images/51/1459128257_2.png",
        @"type":@(1),
        @"url": @"12230107"
    },
                                 @{
                                     @"id":@(2048),
                                     @"pic200": @"http://www.qubaobei.com/ios/images/51/1459162935_2.png",
                                     @"type":@(2),
                                     @"url": @"http://tc.ci123.com/adclick.php?bannerid=10725&m_site=2&m_plat=51&o_user_id=8102917"
                                     },

                                 @{
                                     @"id":@(1671),
                                     @"pic200": @"http://www.qubaobei.com/ios/images/51/1459128152_2.png",
                                     @"type":@(2),
                                     @"url": @"http://tc.ci123.com/adclick.php?bannerid=9833&m_site=2&m_plat=51&o_user_id=8102917"
                                     },

                                 @{
                                     @"id":@(1832),
                                     @"pic200": @"http://www.qubaobei.com/ios/images/51/1458900192_2.png",
                                     @"type":@(2),
                                     @"url": @"http://tc.ci123.com/adclick.php?bannerid=7461&m_site=2&m_plat=51&o_user_id=8102917"
                                     }];
    //_adsData是广告图数据源，从网络中获取到的
    if (!_adsData || ![_adsData isKindOfClass:[NSArray class]]) {
        return;
    }
    
    _adsView.backgroundColor = [UIColor clearColor];
    NSMutableArray *items=[[NSMutableArray alloc] init];
    //使用SGFocusImageFrame库，添加一个个轮播图
    for (NSInteger i = 0; i < _adsData.count; i++) {
        SGFocusImageItem *item=[[SGFocusImageItem alloc] initWithTitle:@""
                                                              imageUrl:_adsData[i][@"pic200"]
                                                                   tag:i
                                                                   url:_adsData[i][@"url"]
                                                                adType:[_adsData[i][@"type"] intValue]
                                                                  adId:_adsData[i][@"id"]];
        [items insertObject:item atIndex:i];
    }
    //使用创建的SGFocusImageItem初始化SGFocusImageFrame
    SGFocusImageFrame *imageFrame = [[SGFocusImageFrame alloc] initWithFrame:CGRectMake(0, 0, width, height)
                                                                    delegate:self
                                                             focusImageItems:items];
    
    //把_adsView 中不是背景图片的subview全部移除掉，这样就可以刷新广告图了
    UIImageView *backImageView = (UIImageView *)[_adsView viewWithTag:TagAdBack];
    for(UIView *view in [_adsView subviews]){
        if (view == backImageView) {
            continue;
        }
        [view removeFromSuperview];
    }
    [_adsView addSubview:imageFrame];
    
}

- (void)foucusImageFrame:(SGFocusImageFrame *)imageFrame didSelectItem:(SGFocusImageItem *)item
{
    SLog(@"did selected me!");
}

-(void)_initView{
    _scrollContentView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, APP_SCREEN_WIDTH, APP_SCREEN_HEIGHT)];
    [_scrollContentView setContentSize:CGSizeMake(APP_SCREEN_WIDTH, 1000)];
    [self.view addSubview:_scrollContentView];
    _scrollContentView.delegate = self;
    
    self.totalHeadOffsetY = 350 - NavHeight;
    self.headViewWidth = APP_SCREEN_WIDTH;
    self.headViewHeight = 224.0f;//204
    
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat offsetY = _scrollContentView.contentOffset.y;
    
    if (offsetY < 0) {
        CGFloat factor = ((ABS(offsetY) + _headViewHeight) * _headViewWidth) / _headViewHeight;
        CGRect f = CGRectMake( - (factor - _headViewWidth) / 2, offsetY, factor, _headViewHeight + ABS(offsetY));
        _headBackView.frame = f;
        CGFloat headLeft = (_headViewWidth - 100) / 2;
        if (offsetY > -80) {
            CGFloat width = 100 - offsetY;
            CGRect headRect = CGRectMake(headLeft + (offsetY / 2), 65 + offsetY, width, width);
            _headWrap.frame = headRect;
            _headWrap.layer.cornerRadius = width / 2;
            
            CGFloat headWidth = width - 10;
            CGRect headImageRect = CGRectMake(5, 5, headWidth, headWidth);
            _head.frame = headImageRect;
            _head.layer.cornerRadius = headWidth / 2;
        }
        _shelter.backgroundColor=[UIUtils getColorByString:AppStyleConfig[appUserType][@"homeColor"]];

    }
}

-(void)_initHeadView
{
    _headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _scrollContentView.width, _headViewHeight)];
    _headView.backgroundColor = DefaultViewBackgroundColor;
    _headView.userInteractionEnabled=YES;
    [_scrollContentView addSubview:_headView];
    
    _headBackView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _headViewWidth, _headViewHeight)];
    _headBackView.backgroundColor= [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeColor"]];
    [_headView addSubview:_headBackView];
    
    _headBackImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, _headView.height - 93, _headView.width, 93)];
    _headBackImage.image = [UIImage imageNamed:AppStyleConfig[appUserType][@"homeHeadBackImage"]];
    _headBackImage.backgroundColor = [UIColor clearColor];
    [_headView addSubview:_headBackImage];
    
    _headWrap = [[UIView alloc] initWithFrame:CGRectMake((_headViewWidth - 100) / 2, 65, 100, 100)];
    _headWrap.backgroundColor = [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeHeadBorderColor"]];
    _headWrap.layer.cornerRadius = 50.0f;
    _headWrap.layer.masksToBounds = YES;
    [_headView addSubview:_headWrap];
    
    _head = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 90, 90)];
    _head.layer.cornerRadius = 45.0f;
    _head.layer.masksToBounds = YES;
    _head.layer.borderWidth = 1.0f;
    _head.layer.borderColor = [UIColor whiteColor].CGColor;
    _head.image = [UIImage imageNamed:@"default_head"];
    [_headWrap addSubview:_head];
    
    _stateTitle = [[UILabel alloc] initWithFrame:CGRectMake((_headViewWidth - 85) / 2, _headWrap.bottom + 15, 85, 28)];
    _stateTitle.userInteractionEnabled = YES;
    _stateTitle.backgroundColor = [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeStateBackColor"]];
    _stateTitle.layer.cornerRadius = 14.0f;
    _stateTitle.layer.masksToBounds = YES;
    _stateTitle.font = [UIFont systemFontOfSize:14.0f];
    _stateTitle.textAlignment = NSTextAlignmentCenter;
    _stateTitle.textColor = [UIColor whiteColor];
    _stateTitle.text=@"StateTItle";
    [_headView addSubview:_stateTitle];
    
    UILabel *stateLeftTitle = [[UILabel alloc] initWithFrame:CGRectMake(26, 165, 100, 15)];
    stateLeftTitle.backgroundColor = [UIColor clearColor];
    stateLeftTitle.font = [UIFont systemFontOfSize:15.0f];
    stateLeftTitle.textColor = [UIColor whiteColor];
    _stateLeftTitle = stateLeftTitle;
    [_headView addSubview:stateLeftTitle];
    _stateLeft = [[UILabel alloc] initWithFrame:CGRectMake(stateLeftTitle.left, stateLeftTitle.bottom + 6, stateLeftTitle.width, 17)];
    _stateLeft.backgroundColor = [UIColor clearColor];
    _stateLeft.font = [UIFont systemFontOfSize:15.0f];
    _stateLeft.textColor = [UIColor whiteColor];
    stateLeftTitle.text = @"leftTitle";
    [_headView addSubview:_stateLeft];
    
    UILabel *stateRightTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 165, stateLeftTitle.width, 15)];
    stateRightTitle.backgroundColor = [UIColor clearColor];
    stateRightTitle.font = [UIFont systemFontOfSize:14.0f];
    stateRightTitle.textColor = [UIColor whiteColor];
    stateRightTitle.textAlignment = NSTextAlignmentRight;
    stateRightTitle.right = _headViewWidth - 26;
    _stateRightTitle = stateRightTitle;
    [_headView addSubview:stateRightTitle];
    _stateRight = [[UILabel alloc] initWithFrame:CGRectMake(stateRightTitle.left, stateRightTitle.bottom + 6, _stateLeftTitle.width, 17)];
    _stateRight.textAlignment = NSTextAlignmentRight;
    _stateRight.backgroundColor = [UIColor clearColor];
    _stateRight.font = [UIFont systemFontOfSize:15.0f];
    _stateRight.textColor = [UIColor whiteColor];
    _stateRight.text = @"deee";
    [_headView addSubview:_stateRight];
    
    //孕期
    _pregHeadWrap = [[UIView alloc] initWithFrame:CGRectMake(20, 75, 70, 70)];
    _pregHeadWrap.backgroundColor = [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeHeadBorderColor"]];
    _pregHeadWrap.layer.cornerRadius = 35.0f;
    _pregHeadWrap.layer.masksToBounds = YES;
    _pregHeadWrap.hidden=YES;
    [_headView addSubview:_pregHeadWrap];
    
    _pregHead = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 60, 60)];
    _pregHead.layer.cornerRadius = 30.0f;
    _pregHead.layer.masksToBounds = YES;
    _pregHead.layer.borderWidth = 1.0f;
    _pregHead.layer.borderColor = [UIColor whiteColor].CGColor;
    _pregHead.image = [UIImage imageNamed:@"default_head"];
    _pregHead.hidden=YES;
    [_pregHeadWrap addSubview:_pregHead];
    
    _pregStateTitle = [[UILabel alloc] initWithFrame:CGRectMake(_pregHeadWrap.right+10, _pregHeadWrap.top + 12, 100, 19)];
    _pregStateTitle.backgroundColor = [UIColor clearColor];
    _pregStateTitle.font = [UIFont boldSystemFontOfSize:18.0f];
    _pregStateTitle.textColor = [UIColor whiteColor];
    [_headView addSubview:_pregStateTitle];
    
    _pregStateLeft = [[UILabel alloc] initWithFrame:CGRectMake(_pregHeadWrap.right+10, _pregStateTitle.bottom + 10, 100, 16)];
    _pregStateLeft.backgroundColor = [UIColor clearColor];
    _pregStateLeft.font = [UIFont systemFontOfSize:15.0f];
    _pregStateLeft.textColor = [UIColor whiteColor];
    [_headView addSubview:_pregStateLeft];
    
    _pregStateRight = [[UILabel alloc] initWithFrame:CGRectMake(_pregStateLeft.right+15, _pregStateLeft.top, 100, 16)];
    _pregStateRight.backgroundColor = [UIColor clearColor];
    _pregStateRight.font = [UIFont systemFontOfSize:15.0f];
    _pregStateRight.textColor = [UIColor whiteColor];
    [_headView addSubview:_pregStateRight];
    
    _pregBorder=[[UILabel alloc] initWithFrame:CGRectMake(15, _pregHeadWrap.bottom+15, APP_SCREEN_WIDTH-15*2, 0.5)];
    _pregBorder.backgroundColor=RGBACOLOR(255, 255, 255, 0.5);
    _pregBorder.hidden=YES;
    [_headView addSubview:_pregBorder];
    
    _pregMoreInfo=[[UILabel alloc] initWithFrame:CGRectMake(18, _pregBorder.bottom+10, APP_SCREEN_WIDTH-18*2, 36)];
    _pregMoreInfo.textColor=[UIColor whiteColor];
    _pregMoreInfo.font=[UIFont systemFontOfSize:14];
    _pregMoreInfo.backgroundColor=[UIColor clearColor];
    _pregMoreInfo.numberOfLines=0;
    _pregMoreInfo.userInteractionEnabled=YES;
   
//    UITapGestureRecognizer *ges=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getMoreHeadKnowledge)];
//    [_pregMoreInfo addGestureRecognizer:ges];
    [_headView addSubview:_pregMoreInfo];
    
    _pregMoreImage=[[UIImageView alloc] initWithFrame:CGRectMake(APP_SCREEN_WIDTH-18-18, _pregMoreInfo.top+20, 13, 13)];
    _pregMoreImage.image=[UIImage imageNamed:@"home_icon_right"];
    _pregMoreImage.userInteractionEnabled=YES;
//    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(getMoreHeadKnowledge)];
//    [_pregMoreImage addGestureRecognizer:tap];
    [_headView addSubview:_pregMoreImage];
    
    //大姨妈
    _yimaHeadView=[[UIImageView alloc] initWithFrame:CGRectMake((_headViewWidth - 109) / 2, 64, 109, 102)];
    _yimaHeadView.image=[UIImage imageNamed:@"home_yima_bg"];
    _yimaHeadView.hidden=YES;
    [_headView addSubview:_yimaHeadView];
    
    _yimaProgressImage=[[UIImageView alloc] initWithFrame:CGRectMake((_yimaHeadView.width-99)/2, (_yimaHeadView.height-85)/2-3 , 99, 85)];
    _yimaProgressImage.image=[UIImage imageNamed:@"home_yima_safe"];
    [_yimaHeadView addSubview:_yimaProgressImage];
    
    _yimaCur=[[UILabel alloc] initWithFrame:CGRectMake(0, 32, _yimaHeadView.width, 15)];
    _yimaCur.text=@"现处于";
    _yimaCur.textColor=RGBCOLOR(144, 188, 29);
    _yimaCur.font=[UIFont systemFontOfSize:14];
    _yimaCur.textAlignment=NSTextAlignmentCenter;
    [_yimaHeadView addSubview:_yimaCur];
    
    _yimaState=[[UILabel alloc] initWithFrame:CGRectMake(0, _yimaCur.bottom+7, _yimaHeadView.width, 20)];
    _yimaState.text=@"";
    _yimaState.textColor=RGBCOLOR(144, 188, 29);
    _yimaState.font=[UIFont boldSystemFontOfSize:20];
    _yimaState.textAlignment=NSTextAlignmentCenter;
    [_yimaHeadView addSubview:_yimaState];
    
    _yimaBoxView=[[UIView alloc] initWithFrame:CGRectMake(0, _yimaHeadView.bottom+13, APP_SCREEN_WIDTH, 43)];
    _yimaBoxView.hidden=YES;
    [_headView addSubview:_yimaBoxView];
    int boxW=_yimaBoxView.width/3;
    int boxH=_yimaBoxView.height;
    
    UIView *leftView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, boxW, boxH)];
    [_yimaBoxView addSubview:leftView];
    _yimaLeftTitle=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, boxW, 14)];
    _yimaLeftTitle.text=@"下次排卵日";
    _yimaLeftTitle.textColor=[UIColor whiteColor];
    _yimaLeftTitle.font=[UIFont systemFontOfSize:13];
    _yimaLeftTitle.textAlignment=NSTextAlignmentCenter;
    [leftView addSubview:_yimaLeftTitle];
    
    _yimaLeft=[[UILabel alloc] initWithFrame:CGRectMake(0, _yimaLeftTitle.bottom+4, boxW, 15)];
    _yimaLeft.textAlignment=NSTextAlignmentCenter;
    _yimaLeft.textColor=[UIColor whiteColor];
    _yimaLeft.font=[UIFont boldSystemFontOfSize:14];
    _yimaLeft.text=@"";
    [leftView addSubview:_yimaLeft];
    
    CALayer *right=[CALayer layer];
    right.frame=CGRectMake(leftView.right-0.5, 0, 0.5f, leftView.height-15);
    right.backgroundColor=[UIColor whiteColor].CGColor;
    [leftView.layer addSublayer:right];
    
    UIView *centerView=[[UIView alloc] initWithFrame:CGRectMake(leftView.right, 0, boxW, boxH)];
    [_yimaBoxView addSubview:centerView];
    UILabel *center1=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, boxW, 14)];
    center1.text=@"今日怀孕几率";
    center1.textColor=[UIColor whiteColor];
    center1.font=[UIFont systemFontOfSize:13];
    center1.textAlignment=NSTextAlignmentCenter;
    [centerView addSubview:center1];
    
    _yimaCenter=[[UILabel alloc] initWithFrame:CGRectMake(0, _yimaLeftTitle.bottom+4, boxW, 15)];
    _yimaCenter.textAlignment=NSTextAlignmentCenter;
    _yimaCenter.textColor=[UIColor whiteColor];
    _yimaCenter.font=[UIFont boldSystemFontOfSize:14];
    _yimaCenter.text=@"";
    [centerView addSubview:_yimaCenter];
    
    UIView *rightView=[[UIView alloc] initWithFrame:CGRectMake(centerView.right, 0, boxW, boxH)];
    [_yimaBoxView addSubview:rightView];
    _yimaRightTitle=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, boxW, 14)];
    _yimaRightTitle.text=@"下次大姨妈";
    _yimaRightTitle.textColor=[UIColor whiteColor];
    _yimaRightTitle.font=[UIFont systemFontOfSize:13];
    _yimaRightTitle.textAlignment=NSTextAlignmentCenter;
    [rightView addSubview:_yimaRightTitle];
    
    _yimaRight=[[UILabel alloc] initWithFrame:CGRectMake(0, _yimaLeftTitle.bottom+4, boxW, 15)];
    _yimaRight.textAlignment=NSTextAlignmentCenter;
    _yimaRight.textColor=[UIColor whiteColor];
    _yimaRight.font=[UIFont boldSystemFontOfSize:14];
    _yimaRight.text=@"";
    [rightView addSubview:_yimaRight];
    
    CALayer *leftBorder=[CALayer layer];
    leftBorder.frame=CGRectMake(0, 0, 0.5f, centerView.height-15);
    leftBorder.backgroundColor=[UIColor whiteColor].CGColor;
    [rightView.layer addSublayer:leftBorder];
    
    _headBorderBottom = [CALayer layer];
    _headBorderBottom.frame = CGRectMake(0, _headViewHeight - 3.5, _headViewWidth, 3.5);
    _headBorderBottom.backgroundColor = [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeHeadViewBorderColor"]].CGColor;
    [_headView.layer addSublayer:_headBorderBottom];
    
    //新年
    _yearBorder=[[UIImageView alloc] initWithFrame:CGRectMake(0, _headViewHeight-10, _headViewWidth, 10)];
    _yearBorder.image=[UIImage imageNamed:@"home_headyearbg"];
    _yearBorder.hidden= appUserType==2 ? NO : YES;
    [_headView addSubview:_yearBorder];

}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated {
    
    [super viewDidAppear:animated];
   }

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
  
    // Dispose of any resources that can be recreated.
}
- (void)_initNavView
{
    self.navTitle.alpha = 0.0f;
    //消息提醒按钮
    _msg = [self createNavRightButtonWithImage:@"home_btn_message" withFrame:CGRectMake(APP_SCREEN_WIDTH- 38 - 13, Status_Gap+ (CUSTOM_NAV_HEIGHT - 33) / 2 , 38, 33) target:self action:@selector(msgRemind:)];
    
    UILabel *mCount = [[UILabel alloc]initWithFrame:CGRectMake(38-17/2-5, -17/2+5, 17, 17)];
    [[mCount layer] setCornerRadius:8.5f];
    [[mCount layer] setMasksToBounds:YES];
    [mCount setBackgroundColor:[UIColor whiteColor]];
    [mCount setFont:[UIFont systemFontOfSize:12.0f]];
    [mCount setTextColor:[UIUtils getColorByString:AppStyleConfig[appUserType][@"navColor"]]];
    [mCount setTextAlignment:NSTextAlignmentCenter];
    [mCount setHidden:NO];
    mCount.text=@"1";
    [_msg addSubview:mCount];
    _mCountLabel = mCount;
    
    //签到和搜索按钮
    _leftView = [[UIView alloc] initWithFrame:CGRectMake(12, Status_Gap+ (CUSTOM_NAV_HEIGHT - 32) / 2, 178, 30)];//225 CUSTOM_NAV_HEIGHT
    _leftView.backgroundColor = [UIUtils getColorByString:AppStyleConfig[appUserType][@"homeSignBackColor"]];
    _leftView.layer.cornerRadius=14;
    _leftView.layer.masksToBounds=YES;
    [self.nav addSubview:_leftView];
    
    //签到按钮
    _signView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 125, 30)];//225 CUSTOM_NAV_HEIGHT
    _signView.backgroundColor = [UIColor clearColor];
    [_leftView addSubview:_signView];
    
    _signImage = [[UIImageView alloc] initWithFrame:CGRectMake(6, (_signView.height - 30) / 2, 30, 30)];
    _signImage.image = [UIImage imageNamed:@"home_icon_sign"];
    _signImage.backgroundColor = [UIColor clearColor];
    [_signView addSubview:_signImage];
    
    _signLabel = [[UILabel alloc] initWithFrame:CGRectMake(_signImage.right + 3, 0, _signView.width - _signImage.width, _signView.height)];
    _signLabel.backgroundColor = [UIColor clearColor];
    _signLabel.text = @"已签到N天";
    _signLabel.font = [UIFont systemFontOfSize:12.5];
    _signLabel.textColor = [UIColor whiteColor];
    [_signView addSubview:_signLabel];
    
    _signRedDot=[[UILabel alloc] initWithFrame:CGRectMake(_signImage.right+68, _signImage.top+3, 7, 7)];
    _signRedDot.backgroundColor=[UIUtils getColorByString:AppStyleConfig[appUserType][@"homeSignDotColor"]];
    _signRedDot.layer.borderColor=RGBCOLOR(255, 255, 255).CGColor;
    _signRedDot.layer.borderWidth=1.0f;
    _signRedDot.layer.cornerRadius=3.5;
    _signRedDot.layer.masksToBounds=YES;
    [_signView addSubview:_signRedDot];
    
    _shelter=[[UIView alloc]initWithFrame:CGRectMake(_signView.right+8, 0,4, 30)];
    _shelter.backgroundColor=[UIUtils getColorByString:AppStyleConfig[appUserType][@"homeColor"]];
    [_leftView addSubview:_shelter];
    
    _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _searchBtn.frame = CGRectMake(_shelter.right+4, (_leftView.height - 32) / 2, 32, 32);
    [_searchBtn setImage:[UIImage imageNamed:@"home_icon_search"] forState:UIControlStateNormal];
    [_searchBtn addTarget:self action:@selector(showSearchView) forControlEvents:UIControlEventTouchUpInside];
    [_leftView addSubview:_searchBtn];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(treeSigned:)];
    [_signView addGestureRecognizer:tap];
    
}
-(void)msgRemind:(id)sender
{
    
}
-(void)showSearchView
{
    
}
-(void)treeSigned:(id)sender
{
    
}

@end